package com.CMUBiS.PageServlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.CMUBiS.Data.GlobalVars;

/**
 * Servlet implementation class BidServlet
 */
@WebServlet("/bid")
public class BidServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BidServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * 
	 * 
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if(GlobalVars.isHTML4){
			//makePage(request, response, Boolean.FALSE);
		}else{
			PrintWriter out = response.getWriter();
			float success = GlobalVars.db.insertBid(Integer.parseInt(request.getParameter("userID")), Integer.parseInt(request.getParameter("itemID")), Integer.parseInt(request.getParameter("quantity")), Float.parseFloat(request.getParameter("bid")),Float.parseFloat(request.getParameter("maxBid")));
			if(success>0){
				out.println("{\"itemID\":\""+request.getParameter("itemID")+"\",\"bid\":\""+success+"\"}");
			}else{
				out.println("{\"itemID\":\""+request.getParameter("itemID")+"\",\"quantity\":\"failed\"}");
			}
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
